package cn.wolfcode.qo;

import lombok.Data;

import java.util.List;
@Data
public class PageResult<T> {
    //封装了页面显示所要的数据
    //当前页
    private int currentPage;
    //每页的数量
    private int pageSize;
    //数据的总数
    private int totalCount;
    //部门信息
    private List<T> data;
    //总页数
    private int totalPage;
    //上一页
    private int prevPage;
    //下一页
    private int nextPage;


    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        // 加入判断，节省计算性能
        if(totalCount <= pageSize) {
            this.totalPage = 1;
            this.prevPage = 1;
            this.nextPage = 1;
            return;
        }

        this.totalPage=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
        this.prevPage=currentPage-1>1?currentPage-1:1;
        this.nextPage=currentPage+1<totalPage?currentPage+1:totalPage;
    }

    public PageResult() {
    }
}
